//
//  CQCoverView.m
//  01-OC微博
//
//  Created by 陈乾 on 15/10/27.
//  Copyright © 2015年 陈乾. All rights reserved.
//

#import "CQCoverView.h"

@implementation CQCoverView
#warning 这样做很方便 在外部调用 只需要接收一下就ok了
+(instancetype)show
{
    //创建蒙板和屏幕一样大
    CQCoverView *view = [[CQCoverView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    //添加到主窗口上面
    [CQKeyWindow addSubview:view];
    //返回
    return view;
}


-(void)setDimBackground:(BOOL)dimBackground
{
    _dimBackground = dimBackground;
    
    if (dimBackground) {
        self.backgroundColor = [UIColor blackColor];
        self.alpha = 0.5;
    }else{
        //没有朦胧效果
        self.alpha = 1;
        self.backgroundColor = [UIColor clearColor];
    }

}

/**
 *点击蒙板
 */
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    //从主窗口移除
    [self removeFromSuperview];
    
    //代理
    if ([self.delegate respondsToSelector:@selector(coverView:)]) {
        [self.delegate coverView:self];
    }
  
}
@end
